/**
 * @param {number[]} arr
 * @return {void} Do not return anything, modify arr in-place instead.
 */
 var duplicateZeros = function(arr) {
  let cnt = arr.filter(e => e === 0).length;
  let i = arr.length - 1;
  while(i >= 0) {
      //console.log(i, i + cnt, cnt, arr[i]);
      if(arr[i] === 0) {
          cnt --;
          if(i + cnt < arr.length) {
              arr[i + cnt] = 0;
          }
          if(i + cnt + 1 < arr.length) {
              arr[i + cnt + 1] = 0;
          }
      } else {
          if(i + cnt < arr.length) {
              arr[i + cnt] = arr[i];
          }
      }
      i--;
  }
};